<template>
	<view class="index-page page">
		<CustomNav :normal="{ textColor: '#fff', background: '#FF2F34' }" title="积分商城" :is-back="true"></CustomNav>
		<view class="content">
			<view class="top-block">
				<view class="search-block">
					<view class="input-block">
						<view class="input-left">
							<image
								src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/search.png"
								mode=""></image>
							<input placeholder="请输入关键字" v-model="goodsName" @confirm="search" />
						</view>
						<view class="search" @click="search">
							搜索
						</view>
					</view>
				</view>
			</view>
			<view class="info-block">
				<view class="classify-tab-block">
					<view class="tab-content" style="flex-grow: 1;">
						<view :class="status==''?'active':''" class="tab-item" @click="getMallTypeAll()">全部</view>
						<view @click="getMallType(item.id)" :class="status==item.id?'active':''" class="tab-item"
							v-for="(item,index) in tabList" :key="item.id">{{item.name}}</view>
					</view>
				</view>
				<template v-if="list.length>0">
					<view class="activity-item" v-for="(item,index) in list" :key="item.id"
						@click="navigate('/page_other/integral_store/info?id='+item.id)">
						<view class="activity-top">
							<view class="title">
								{{item.goodsName}}
							</view>
						</view>
						<view class="activity-middle">
							<image :src="cloudStorage+item.goodsFace" mode=""></image>
							<view class="middle-right">
								<view class="info-top">
									<view class="info-title">
										{{item.goodsName}}
									</view>
									<view class="involution">
										共{{item.number}}件
									</view>
								</view>
								<view class="info-time" style="display: flex;">
									￥{{item.integral}}积分
									<view v-if="item.voucher">
										+{{item.voucher}}券
									</view>
								</view>
							</view>
						</view>
						<view class="activity-bottom">
							<view class="cancel">
								下单时间：{{ item.createTime }}
							</view>
							<view v-if="item.status==7" class="top-right" style="color: #60DC4D;">
								待核销
							</view>
							<view v-if="item.status==1" class="top-right" style="color: #60DC4D;">
								待发货
							</view>
							<view v-if="item.status==2" class="top-right" style="color: #60DC4D;">
								待收货
							</view>
							<view v-if="item.status==3" class="top-right" style="color: #767676;">
								已完成
							</view>
							<view v-if="item.status==4" class="top-right" style="color: #FF601D;">
								售后申请中
							</view>
							<view v-if="item.status==5" class="top-right" style="color: #FF2F34;">
								已拒绝
							</view>
							<view v-if="item.status==6" class="top-right" style="color: #0055DE;">
								已退款
							</view>
						</view>
					</view>
				</template>
				<view v-if="more==false&&list.length==0" style="width:100%;text-align: center;">暂无数据</view>
				<view v-else-if="more==false&&list.length>0" style="width:100%;text-align: center;">没有更多了</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getIntegralOrderList
	} from '@/api/integral.js';
	import {
		isMore
	} from '@/util/util.js'

	export default {
		data() {
			return {
				status: '',
				goodsName: '',
				conf: {
					page: 1,
					limit: 10,
				},
				more: true,
				list: [],
				tabList: [
					{
							id: 7,
							name: '待核销'
						},
					{
						id: 1,
						name: '待发货'
					},
					{
						id: 2,
						name: '待收货'
					},
					{
						id: 3,
						name: '已完成'
					},
				],
			};
		},
		methods: {
			search() {
				this.getIntegralOrderList(true)
			},
			getMallTypeAll() {
				this.status = ''
				this.getIntegralOrderList(true)
			},
			getMallType(e) {
				this.status = e
				this.conf.page = 1
				this.getIntegralOrderList(true)
			},
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getIntegralOrderList(true)
			},
			//用户查询订单
			getIntegralOrderList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getIntegralOrderList({
					page: this.conf.page,
					limit: this.conf.limit,
					status: this.status,
					goodsName: this.goodsName,
				}).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				})
			},
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getIntegralOrderList()
			}
		},
		onLoad(e) {
			this.status = e.status
			this.getIntegralOrderList(true)
		},
		onshow()
		{
			this.getIntegralOrderList()
		}
	};
</script>

<style scoped lang="scss">
	.index-page {
		width: 100%;
		height: 100%;

		.content {
			width: 100%;
			margin-top: 160rpx;

			.top-block {
				width: 100%;
				height: 220rpx;
				background-color: #FF2F34;
				padding: 30rpx;
			}

			.search-block {
				width: 100%;
				height: 70rpx;
				display: flex;


				.address-block {
					display: flex;
					background-color: #FFFFFF;
					align-items: center;
					justify-content: center;
					width: 130rpx;
					border-radius: 50px;
					margin-right: 20rpx;

					image {
						width: 30rpx;
						height: 30rpx;
						margin-right: 5rpx;
					}

					.address {
						color: #FF2F34;
						font-size: 28rpx;
					}
				}

				.input-block {
					display: flex;
					background-color: #FFFFFF;
					border-radius: 50px;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					padding: 6rpx 6rpx 6rpx 20rpx;

					.input-left {
						width: calc(100% - 140rpx);
						display: flex;

						image {
							width: 30rpx;
							height: 30rpx;
							// margin-right: 5rpx;
							margin: 7rpx 7rpx 0 0;
						}

						input {
							border-radius: 50px;
							width: 100%;

						}
					}

					.search {
						display: flex;
						justify-content: center;
						align-items: center;
						width: 130rpx;
						border-radius: 50rpx;
						height: 100%;
						padding-bottom: 5rpx;
						color: #FFFFFF;
						background: linear-gradient(90deg, #FF2F34 0%, #FF6B18 100%);
					}
				}
			}

			.info-block {
				background-color: #f7f6f9;
				border-radius: 50rpx 50rpx 0 0;
				padding: 30rpx;
				margin-top: -60rpx;

				.classify-tab-block {
					width: 100%;
					display: flex;
					justify-content: center;
					align-items: center;

					.tab-content {
						display: flex;
						justify-content: space-between;

						.tab-item {
							padding: 10rpx;
							font-size: 30rpx;
							margin-right: 20rpx;
							flex: none;
							color: #FF2F34;
						}

						.tab-item.active {
							font-size: 32rpx;
							color: #FF2F34;
							font-family: 'FangZhengHanZhenGuangBiaoJianTi';
						}
					}

					.iconfont {
						font-size: 32rpx;
						font-weight: bold;
						color: #fff;
					}
				}


				.activity-item {
					padding: 24rpx 30rpx 20rpx;
					background-color: #FFFFFF;
					border-radius: 20rpx;
					margin-bottom: 20rpx;
					margin-top: 20rpx;

					.activity-top {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-bottom: 26rpx;

						.title {
							font-size: 32rpx;
							font-weight: bold;
							line-height: normal;
							letter-spacing: 0em;
							color: #1A1A1A;
						}
					}

					.activity-middle {
						display: flex;

						image {
							width: 120rpx;
							height: 120rpx;
							margin-right: 20rpx;
							border-radius: 20rpx;
						}

						.middle-right {
							width: calc(100% - 140rpx);
							display: flex;
							flex-direction: column;
							justify-content: space-around;

							.info-top {
								width: 100%;
								display: flex;
								justify-content: space-between;

								.info-title {
									width: calc(100% - 120rpx);
									font-size: 30rpx;
								}

								.involution {
									width: 120rpx;
									text-align: end;
									color: #767676;
									font-size: 28rpx;
								}
							}

							.info-time {
								font-size: 28rpx;
								font-weight: bold;
								line-height: normal;
								letter-spacing: 0em;
								color: #1A1A1A;
							}
						}
					}

					.activity-bottom {
						display: flex;
						margin-top: 26rpx;
						justify-content: space-between;

						.cancel {
							font-size: 28rpx;
						}

						.top-right {
							font-size: 28rpx;
						}
					}
				}
			}
		}
	}
</style>